package entitys;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
public class Remito implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1991671024627446690L;
	private int idRemito;
	private Date fechaEmision;
	private List<ItemRemito> items;
	private SolicitudCompra solicitudCompra;
	
	public Remito() {
		super();
		items = new ArrayList<ItemRemito>();
	}
	@Id	
    @Column(name = "idRemito", nullable = false)
	public int getIdRemito() {
		return idRemito;
	}

	public void setIdRemito(int idRemito) {
		this.idRemito = idRemito;
	}

	public Date getFechaEmision() {
		return fechaEmision;
	}

	public void setFechaEmision(Date fechaEmision) {
		this.fechaEmision = fechaEmision;
	}
	
    @OneToMany(cascade=CascadeType.ALL)
    @LazyCollection(LazyCollectionOption.FALSE)
    @JoinColumn(name = "idRemito")
	public List<ItemRemito> getItems() {
		return items;
	}

	public void setItems(List<ItemRemito> items) {
		this.items = items;
	}
	
	@OneToOne(mappedBy="remito")
	public SolicitudCompra getSolicitudCompra() {
		return solicitudCompra;
	}
	public void setSolicitudCompra(SolicitudCompra solicitudCompra) {
		this.solicitudCompra = solicitudCompra;
	}
	public void addItem(ItemRemito oItem){
		items.add(oItem);
	}
}